<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

  <input type="text" id="userID2">
  <input type="text" id="data">
  <button onclick="onclicksend()">发送</button >
    <script>
      
        id = 456
    	//与本地计算机通信
        const ws = new WebSocket('ws://localhost:8088/ws?userID='+id)
        //与其他计算机通信
        //const ws = new WebSocket('ws://服务器地址:端口号')
        function onclicksend(){
            var userID2= document.getElementById("userID2").value;
            var data= document.getElementById("data").value;

        var message = {
      userID1: ""+id,
      userID2: userID2,
      data: data
    };
    var messageString = JSON.stringify(message);
    var sendData ={
        type:1,
        content:messageString
    }
    console.log(sendData);
    var jsonStr = JSON.stringify(sendData);
    ws.send(jsonStr);
        }
        ws.onopen = function () {
	        console.log('我们连接成功啦...')
	        // ws.send(11);
        }
        ws.onerror = function () {
        	console.log('连接失败了...')
        }
        ws.onmessage = function (e) {
	        console.log('服务端推送数据: ' + e.data)
        }
        ws.onclose = function () {
        	console.log('连接关闭了...')
        }

    </script>
</body>
</html>
